package hc.bre.data.encoder
import hc.bre.ComponentConfig
import hc.bre.cmn.*

@groovy.transform.CompileStatic
@groovy.transform.ToString(includeNames=true,includePackage=false)
class EncoderDefinition extends RuleDefinition{
	public static final ComponentConfig _config ;
	static {
		_config = new ComponentConfig();
		_config.rtype = 'data:encoder';
		_config.rname = '业务编码定义';
		_config.builderClass = EncoderBuilder;
		_config.resultStruct = new EncoderStruct();
		_config.objectpage = '/rule/EncoderEditor.htm?rpath=${rpath}';
		_config.description = '''
业务编码负责对业务的某些事物、行为、属性等进行统一的命名和编码，便于规范、简化、追踪相关事项。
''';
	};
	
	int depth ;

	List<EncoderItem> list=[];
	@Override
	public EncoderDefinition load(Map map) {
		super.load(map);
		
		depth = map['depth']?map['depth']as Integer:0;

		list = hc.Util.loadList(map['list'], EncoderItem.class)
		
		return this;
	}

	public EncoderItem find(int id) {
		return TreeOption.findFrom(id, this.list);
	}
	
	public String accessRouteOf(int id) {
		List<EncoderItem> lst = EncoderItem.routeFrom(id, this.list);
		return lst.collect{it.code}.join('.')
	}
}
